import { request } from '@/utils/request'
import type {
  TopDep,
  Picture,
  PayPreType,
  ConsultPatial
} from '@/types/consult'
import type { PatientType } from '@/types/patient'
import type {
  KnowledgePage,
  KnowledgeQueryType,
  DoctorRes,
  FollowTargetType,
  PayInfoType,
  ConsultOrderItem
} from '@/types/consult'
import type { ConsultType } from '@/enums'
// 获取文章列表的接口 type current pageSize
export const reqGetKnowledgeList = (data: KnowledgeQueryType) =>
  request<KnowledgePage>('patient/home/knowledge', 'GET', data)
//获取关注医生的列表
export const reqGetFollowDoctors = (data: {
  current: number
  pageSize: number
}) => request<DoctorRes>('home/page/doc', 'GET', data)

// 关注接口  复用的接口 topic百科话题,knowledge百科文章,doc医生,disease疾病
export const reqFollowTarget = (data: { type: FollowTargetType; id: string }) =>
  request('like', 'POST', data)
// 获取所有科室
export const reqGetAllDep = () => request<TopDep[]>('dep/all')

// 上传图片接口
export const reqUpload = (file: File) => {
  // 将文件对象收集到formData中
  const fm = new FormData()
  fm.append('file', file)
  return request<Picture>('upload', 'post', fm)
}

// 生成预支付信息
export const reqGetPayInfoPre = (data: PayPreType) =>
  request<PayInfoType>('patient/consult/order/pre', 'GET', data)

// 获取患者信息
export const reqGetPatientInfo = (id: string) =>
  request<PatientType>(`patient/info/${id}`)
// 生成订单
export const reqCreateOrder = (data: ConsultPatial) =>
  request<{ id: string }>('patient/consult/order', 'POST', data)

// 支付

export const reqPay = (data: {
  paymentMethod: 0 | 1 | 2
  orderId: string
  payCallback: string
}) => request<{ payUrl: string }>('patient/consult/pay', 'POST', data)

// 订单信息获取
export const reqGetOrderDetail = (orderId: string) =>
  request<ConsultOrderItem>('patient/consult/order/detail', 'GET', { orderId })
// 获取处方信息
export const reqGetpreDetail = (id: string) =>
  request<{ url: string }>(`patient/consult/prescription/${id}`)
// 提交对医生评价
export const reqEvaluate = (data: {
  docId: string
  orderId: string
  score: number
  content: string
  anonymousFlag: 1 | 0
}) => request<{ id: string }>('patient/order/evaluate', 'POST', data)

// 问诊记录
export const reqGetConsultList = (params: {
  current: number
  pageSize: number
  type: ConsultType
}) =>
  request<{ pageTotal: number; total: number; rows: ConsultOrderItem[] }>(
    'patient/consult/order/list',
    'GET',
    params
  )

// 取消问诊
export const reqCancelOrder = (id: string) =>
  request(`patient/order/cancel/${id}`, 'PUT')
// 删除订单
export const reqDelOrder = (id: string) =>
  request(`patient/order/${id}`, 'DELETE')
